package com.datastructure.test.isvalidbucket;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Stack;

public class IsValidBucket {

    public static void main(String[] args) {
        IsValidBucket isValidBucket = new IsValidBucket();
        boolean valid = isValidBucket.isValid("([)]");
        System.out.println(valid);
    }

    public boolean isValid (String s) {
        // write code here
        if(s.length()==1){
            return false;
        }
        Stack<Byte> second = new Stack<>();
        byte[] bytes = s.getBytes();
        for (Byte next : bytes) {
            if (second.size() == 0) {
                second.add(next);
            } else {
                Byte pop = second.pop();
                if (!((next + pop) == 248 || (next + pop) == 184 || (next + pop) == 81)) {
                    second.add(pop);
                    second.add(next);
                }
            }
        }
        return second.size() == 0;
    }
}
